package com.mobile.check.bluetooth;

import java.io.UnsupportedEncodingException;

import com.mobile.check.util.CHexConver;

/**
 * 蓝牙通信的SPP客户端
 * @version 1.0 2013-03-17
 * @author JerryLi (lijian@dzs.mobi)
 * */
public final class BluetoothSppClient extends BTSerialComm{
	public static final byte IO_MODE_HEX = 1;
	public static final byte IO_MODE_STRING = 2;
	private byte[] mbtEndFlg = null;
	private byte mbtRxDMode = 2;
	private byte mbtTxDMode = 2;
	protected String msCharsetName = null;

	public BluetoothSppClient(String var1) {
		super(var1);
	}

	public String Receive() {
		byte[] var1 = this.ReceiveData();
		if (var1 != null) {
			return 1 == this.mbtRxDMode ? CHexConver.convertData(var1) : new String(var1);
		} else {
			return null;
		}
	}

	public String ReceiveStopFlg() {
		if (this.mbtEndFlg == null) {
			return new String();
		} else {
			byte[] var1 = this.ReceiveData_StopFlg(this.mbtEndFlg);
			if (var1 == null) {
				return null;
			} else if (this.msCharsetName == null) {
				return new String(var1);
			} else {
				try {
					String var2 = new String(var1, this.msCharsetName);
					return var2;
				} catch (UnsupportedEncodingException var3) {
					return new String(var1);
				}
			}
		}
	}

	public int Send(String var1) {
		if (1 == this.mbtTxDMode) {
			return CHexConver.checkHexStr(var1) ? this.SendData(CHexConver.hexStr2Bytes(var1)) : 0;
		} else if (this.msCharsetName != null) {
			try {
				int var2 = this.SendData(var1.getBytes(this.msCharsetName));
				return var2;
			} catch (UnsupportedEncodingException var4) {
				return this.SendData(var1.getBytes());
			}
		} else {
			return this.SendData(var1.getBytes());
		}
	}

	public byte getTxdMode() {
		return this.mbtTxDMode;
	}

	public void setCharset(String var1) {
		this.msCharsetName = var1;
	}

	public void setReceiveStopFlg(String var1) {
		this.mbtEndFlg = var1.getBytes();
	}

	public void setRxdMode(byte var1) {
		this.mbtRxDMode = var1;
	}

	public void setTxdMode(byte var1) {
		this.mbtTxDMode = var1;
	}

}
